//
//  SplashScreen.m
//  XYLib
//
//  Created by fantasy on 2021/6/9.
//

#import "SplashScreen.h"

static UIView* splashView = nil;
static bool show = false;

@implementation SplashScreen

WX_EXPORT_METHOD(@selector(showSplash))
WX_EXPORT_METHOD(@selector(hideSplash))

+ (void)show {
    if (show) {
        return;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        show = true;
        UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
        splashView = [[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil][0];
        splashView.frame = window.bounds;
        [window addSubview:splashView];
    });
}

+ (void)hide {
    dispatch_async(dispatch_get_main_queue(), ^{
        show = false;
        [splashView removeFromSuperview];
    });
}

- (void)hideSplash {
    [SplashScreen hide];
}

- (void)showSplash {
    [SplashScreen show];
}

@end
